cmake_minimum_required(VERSION 2.6)

PROJECT(libcloak)

SET(VERSION "0.4.1")


SET(CPACK_PACKAGE_VENDOR "Chris Johnson")
SET(CPACK_PACKAGE_CONTACT "Chris Johnson <grundee@gmail.com>")

SET(CPACK_PACKAGE_VERSION_MAJOR "0")
SET(CPACK_PACKAGE_VERSION_MINOR "4")
SET(CPACK_PACKAGE_VERSION_PATCH "1")

SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/libcloak_desc.txt")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The Cloak Resource Manager Library")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")

SET(CPACK_GENERATOR "DEB")
SET(CPACK_SOURCE_GENERATOR "TGZ")

SET(CPACK_SOURCE_PACKAGE_FILE_NAME "libcloak-${VERSION}-src")

set(CPACK_SOURCE_IGNORE_FILES
		  "/CMakeFiles/;CPackSourceConfig.cmake;CPackConfig.cmake;install_manifest.txt;cmake_install.cmake;/_CPack_Packages/;CMakeCache.txt;/install/;/.hg/;.hgtags;~$;.tar.gz$;Makefile;${CPACK_SOURCE_IGNORE_FILES}")


INCLUDE(CPack)

SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake-modules")

IF(NOT CMAKE_BUILD_TYPE)
  SET(CMAKE_BUILD_TYPE release CACHE STRING
      "Choose the type of build, options are: debug release"
      FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)


OPTION(libcloak_CURL
	"Build the project with CURL support" ON)

OPTION(libcloak_XML
	"Build the project with XML support" ON)

OPTION(libcloak_IMAGE
	"Build the project with sdl_image support" ON)

SET(libSources ${libSources} "src/Resource.cpp" "src/TextResource.cpp" "src/XmlResource.cpp" "src/ImageResource.cpp" "src/Handler.cpp" "src/Manager.cpp" "src/Cloak.cpp")
SET(libIncludes ${libIncludes} "include/Resource.h" "include/TextResource.h" "include/XmlResource.h" "include/ImageResource.h" "include/Manager.h" "include/Handler.h" "include/Globals.h" "include/Cloak.h")
SET(testSources ${testSources} "src/test.cpp")
SET(includeDirs ${includeDirs} "${CMAKE_SOURCE_DIR}/include")

IF(libcloak_XML)
	SET(includeDirs ${includeDirs} "${CMAKE_SOURCE_DIR}/tinyxml")
	ADD_LIBRARY(tinyxml "tinyxml/tinyxml.cpp" "tinyxml/tinyxml.h"
			    "tinyxml/tinyxmlerror.cpp"
			    "tinyxml/tinyxmlparser.cpp"
			    "tinyxml/tinystr.cpp"
			    "tinyxml/tinystr.h")

	SET(libIncludes ${libIncludes} "tinyxml/tinyxml.h")

	SET_TARGET_PROPERTIES(tinyxml PROPERTIES COMPILE_FLAGS "-fPIC ${myCFLAGS}")
	SET(optLibs ${optLibs} tinyxml)
	ADD_DEFINITIONS(-DHAVE_XML)
ENDIF(libcloak_XML)

INCLUDE_DIRECTORIES(${includeDirs})
ADD_LIBRARY(cloak SHARED ${libSources} ${libIncludes})
ADD_EXECUTABLE(libcloak-test ${testSources} ${testIncludes})

IF(libcloak_CURL)
	FIND_PACKAGE(CURL)
	IF(CURL_FOUND)
		INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
		SET(optLibs ${optLibs} ${CURL_LIBRARIES})
		ADD_DEFINITIONS(-DHAVE_CURL)
	ELSE(true)
		MESSAGE(FATAL_ERROR "Cannot find CURL libraries")
	ENDIF(CURL_FOUND)
ELSE(true)
ENDIF(libcloak_CURL)	

IF(libcloak_IMAGE)
	FIND_PACKAGE(SDL)
	FIND_PACKAGE(SDLIMAGE)
	IF(SDL_FOUND AND SDLIMAGE_FOUND)
		INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
		INCLUDE_DIRECTORIES(${SDLIMAGE_INCLUDE_DIR})
		SET(optLibs ${optLibs} ${SDL_LIBRARIES})
		SET(optLibs ${optLibs} ${SDLIMAGE_LIBRARIES})
		ADD_DEFINITIONS(-DHAVE_IMAGE)
	ELSE(true)
		MESSAGE(FATAL_ERROR "Cannot find SDL libraries")
	ENDIF(SDL_FOUND AND SDLIMAGE_FOUND)
ELSE(true)
ENDIF(libcloak_IMAGE)

IF(libcloak_CURL)
	MESSAGE("Compiling WITH curl support")
ELSE(true)
	MESSAGE("Compiling WITHOUT curl support")
ENDIF(libcloak_CURL)

IF(libcloak_XML)
	MESSAGE("Compiling WITH xml support")
ELSE(true)
	MESSAGE("Compiling WITHOUT xml support")
ENDIF(libcloak_XML)

IF(libcloak_IMAGE)
	MESSAGE("Compiling WITH sdl_image support")
ELSE(true)
	MESSAGE("Compiling WITHOUT sdl_image support")
ENDIF(libcloak_IMAGE)

TARGET_LINK_LIBRARIES(cloak ${optLibs})
TARGET_LINK_LIBRARIES(libcloak-test cloak)

INSTALL_FILES(/include/cloak FILES ${libIncludes})
INSTALL_TARGETS(/lib RUNTIME_DIRECTORY /bin cloak)
